package org.jradweb.core.taglib;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class UriParameterTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6609164022252084442L;

	private String name;
	private Object value;
	private Boolean inUri = true;

	public Boolean getInUri() {
		return inUri;
	}

	public void setInUri(Boolean inUri) {
		this.inUri = inUri;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	@Override
	public int doEndTag() throws JspException {
		Map<String, Object> map =null;
		if (inUri) {
			map= (Map<String, Object>) pageContext
					.getAttribute(UriTag.URI_PARAMETERS);
			if (map == null) {
				map = new HashMap<String, Object>();
				pageContext.setAttribute(UriTag.URI_PARAMETERS, map);
			}
		}else{
			map= (Map<String, Object>) pageContext
			.getAttribute(UriTag.URI_QURY_PARAMETERS);
			if (map == null) {
				map = new HashMap<String, Object>();
				pageContext.setAttribute(UriTag.URI_QURY_PARAMETERS, map);
			}

		}
		map.put(name, value);

		return super.doEndTag();
	}
}
